//
//  HMNewFeatureViewController.swift
//  Weibo
//
//  Created by xiongminghua on 16/7/25.
//  Copyright © 2016年 熊明华. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"

// item的数量
private let ItemCount = 4

class HMNewFeatureViewController: UICollectionViewController {
    
    /// 布局属性
    let layout = UICollectionViewFlowLayout()
    
    // 构造函数，创建布局属性; 在这个构造函数里面给collectionView初始化一个layout
    init () {
        
        super.init(collectionViewLayout: layout)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // 注册cell
        self.collectionView!.registerClass(HMNewFeautreCell.self, forCellWithReuseIdentifier: reuseIdentifier)
        
        setupLayout()
    }
    
    
    // MARK: - 私有方法
    /// 流水布局
    private func setupLayout() {
        
        // 设置大小
        layout.itemSize = UIScreen.mainScreen().bounds.size
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
        
        // 分页
        collectionView?.pagingEnabled = true
        collectionView?.bounces = false
        
    }

}

 // MARK: UICollectionViewDataSource
/// 拓展分类
extension HMNewFeatureViewController {
    
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return ItemCount
    }
    
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        // 使用自定义cell
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! HMNewFeautreCell
        
        // 配置cell
       // cell.backgroundColor = UIColor.randomColor()
        
        cell.image = UIImage(named: "new_feature_\(indexPath.item + 1)")
        
        // 只有最后一页才需要显示按钮
        if indexPath.item == ItemCount - 1 {
            
            cell.showButtons(true)
        } else {
            cell.showButtons(false)
        }
        
        
        return cell
    }

}

